﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace QuantumFractals.Tests
{
    [TestClass]
    public class QRendererTest
    {
        public QRendererTest()
        {
        }

        private TestContext testContextInstance;

        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void TestHistoriogram()
        {
            QRenderer r = new QRenderer(1000, 100);
            QFractal f = new QFractal(0.61803398874989288039384209090709,
                new QPoint[] {
                    new QPoint(0, 0, 1.0), 
                    new QPoint(0.9428090415820634,0,-0.3333333333333333),
                    new QPoint(-0.4714045207910317,0.816496580927726,-0.3333333333333333),
                    new QPoint(-0.4714045207910317, -0.816496580927726, -0.3333333333333333)});

            for (int t = 0; t < 1000000; t++)
                r.AddPoint(f.CalculateNextPoint());

            SortedDictionary<int, int> c = r.Historiogram.Front;
            Assert.IsTrue(c.Keys.Count > 100);
            using(StreamWriter sw = new StreamWriter(@"C:\Historiogram.csv"))
            {
                foreach(int k in c.Keys)
                    sw.WriteLine(k.ToString(), c[k].ToString());
            }
        }

        [TestMethod]
        public void TestLogHistoriogram()
        {
            QRenderer r = new QRenderer(1000, 100);
            QFractal f = new QFractal(0.61803398874989288039384209090709,
                new QPoint[] {
                    new QPoint(0, 0, 1.0), 
                    new QPoint(0.9428090415820634,0,-0.3333333333333333),
                    new QPoint(-0.4714045207910317,0.816496580927726,-0.3333333333333333),
                    new QPoint(-0.4714045207910317, -0.816496580927726, -0.3333333333333333)});

            for (int t = 0; t < 1000000; t++)
                r.AddPoint(f.CalculateNextPoint());
            //SortedDictionary<int, int> c = r.GetDensityLogHistoriogram(1.000001, FractalObserver.Front);
        }

        [TestMethod()]
        public void ColorTest()
        {
            int i = 0x123456;
            int r = i / 0x10000 % 0x100;
            int g = i / 0x100 % 0x100;
            int b = i % 0x100;
            Assert.AreEqual(0x12, r);
            Assert.AreEqual(0x34, g);
            Assert.AreEqual(0x56, b);
        }
    }
}
